package com.wakala.employment.fragment.other;

import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.CenterPopupView;
import com.wakala.employment.R;
import com.wakala.employment.core.webview.BaseWebViewFragment;
import com.wakala.employment.databinding.FragmentUserIntegralRechargeBinding;
import com.wakala.employment.utils.Utils;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.enums.CoreAnim;
import com.xuexiang.xui.utils.XToastUtils;
import com.xuexiang.xui.widget.actionbar.TitleBar;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link UserIntegralRechargeFragment#} factory method to
 * create an instance of this fragment.
 */
@Page(anim = CoreAnim.none)
public class UserIntegralRechargeFragment extends BaseWebViewFragment<FragmentUserIntegralRechargeBinding> implements View.OnClickListener {

        private Handler mHandler = new Handler(Looper.getMainLooper());


        @NonNull
        @Override
        protected FragmentUserIntegralRechargeBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
            return FragmentUserIntegralRechargeBinding.inflate(inflater, container, attachToRoot);
        }

        @Override
        protected TitleBar initTitle() {
            TitleBar titleBar = super.initTitle();
            titleBar.setTitle("积分充值");
            titleBar.setTitleColor(R.color.white);
            titleBar.setLeftTextColor(R.color.white);
            titleBar.setLeftImageDrawable(getResources().getDrawable(R.drawable.icon_arrow_white));
            titleBar.setBackgroundResource(R.color.colorBgKingYellow);//设置标题栏背景
            //StatusBarUtil.setLightMode(getActivity());
            //设置状态栏背景颜色，如果设置为 Color.TRANSPARENT 将会隐藏状态栏
            getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.colorBgKingYellow));
            return titleBar;
        }

        @Override
        protected void initViews() {
            mAgentWeb = Utils.createAgentWeb(this, binding.container, "file:///android_asset/appcz/index.html");
            mAgentWeb.getJsInterfaceHolder().addJavaObject("Android", new AndroidInterface());
        }

        @Override
        public void onClick(View view) {

        }

        public  class AndroidInterface {

            @JavascriptInterface
            public void callAndroid(final String msg) {
                XToastUtils.toast("这是Js调用Android的方法，内容:" + msg);
            }
            @JavascriptInterface
            public void  toList(){
                openNewPage(UserIntegralRecordFragment.class);
                //XToastUtils.toast("这是Js调用Android的方法，内容:);
            }
            @JavascriptInterface
            public void  recharge(){
                new XPopup.Builder(getContext()).asCustom(new CenterPopupView(requireContext()) {
                    @Override
                    protected int getImplLayoutId() {
                        return R.layout.dialog_alter;
                    }

                    @Override
                    protected void onCreate() {
                        super.onCreate();
                        findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dismiss();
                            }
                        });
                        TextView title = findViewById(R.id.txt_dialog_content);
                        title.setText("尊敬的用户，河狸帮给新用户赠送免费体验会员功能权益，您无需充值，就可免费使用所有会员功能，权益截至时间请关注系统通知消息");
                    }
                }).show();
            }


        }

    }